//index.js
import {
  Get,
  Post,
  JsonPost
} from "../../utils/request.js"
//获取应用实例
const app = getApp()

Page({
  data: {
    // table栏与顶部的距离
    topheight: 0,
    // 是否吸顶
    onTop: false,
    //已触底
    chudi: false,
    jiazai: false,
    // 轮播图
    background: [1, 1, 1],
    //  菜单栏列表
    typeList: [
      {name:'免费设计',page:'design',imgUrl:'/img/homePage/navIcon1.png'},
      {name:'瓷砖',id:10,page:'goSearch',imgUrl:'/img/homePage/navIcon2.png'},
      {name:'岩板',id:11,page:'goSearch',imgUrl:'/img/homePage/navIcon3.png'},
      {name:'大理石',id:12,page:'goSearch',imgUrl:'/img/homePage/navIcon4.png'},
      {name:'优选套餐',page:'goodTC',imgUrl:'/img/homePage/navIcon5.png'},
      {name:'社区体验',page:'commTY',imgUrl:'/img/homePage/navIcon6.png'},
      {name:'旧房翻新',page:'oldRenov',imgUrl:'/img/homePage/navIcon7.png'},
      {name:'算砖神器',page:'jisuanBrick',imgUrl:'/img/homePage/navIcon8.png'},
      // {name:'连锁门店',page:'storeList',imgUrl:'/img/homePage/navIcon9.png'},
      // {name:'装修案例',page:'JXGY',imgUrl:'/img/homePage/navIcon10.png'},
    ],
    list:[1,1,1,1],
    // 广播文案
    radioText:[],
    radioLength:null,
    wpxIos:false,
    JXimg:[],
    newAieModel:false,
    login:false,
  },
  onLoad: function () {
    this.setData({
      wpxIos: getApp().globalData.wpxIos,
      newAieModel: !getApp().globalData.login,
      login: getApp().globalData.login,
    })
    // let that = this
    // wx.createSelectorQuery().selectAll('.radioText').boundingClientRect(function (rect) {
    //   that.setData({
    //     radioLength: rect[0].width
    //   })
    // }).exec();
    this.getInfo()
    this.getJX()
  },
  // 获取用户信息
  bindGetUserInfo(e) {
    getApp().ttClogin()
    getApp().userInfoReadyCallback = () => {
      this.setData({
        login: true
      })
    }
  },
  getInfo(){
    JsonPost('index/homepage').then(res=>{
      this.setData({
        background:res.data.banner,
        homepage_img:res.data.homepage_img,
        marble:res.data.marble,
        ceramic_tile:res.data.ceramic_tile,
        slate:res.data.slate,
      })
    })
  },

    
  getJX(){
    JsonPost('craftsmanship/cate').then(res=>{
      this.setData({
        JXimg:res.data,
      })
    })
  },

  goJX(e){
    wx.navigateTo({
      url: '/pages/JXGY/JXGY?id='+e.currentTarget.dataset.id,
    })
  },

  // 直播
  goLivePlay(){
    let roomId = [1] // 填写具体的房间号，可通过下面【获取直播房间列表】 API 获取
    let customParams = encodeURIComponent(JSON.stringify({
      path: 'pages/livePlay/livePlay',
      pid: 1
    })) // 开发者在直播间页面路径上携带自定义参数（如示例中的path和pid参数），后续可以在分享卡片链接和跳转至商详页时获取，详见【获取自定义参数】、【直播间到商详页面携带参数】章节（上限600个字符，超过部分会被截断）
    wx.navigateTo({
      url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
    })
  },

  
  goWeb(e){
    return
    let url=e.currentTarget.dataset.url
    if (url.indexOf("id=")!=-1) {
      wx.navigateTo({
        url: '/pages/goodsDetail/goodsDetail?goods_id='+url.split("id=")[1]
      })
    }else{
      wx.navigateTo({
        url: '/pages/webView/webView?url='+url,
      })
    }
  },


  goPage(e){
    this.closeNew()
    console.log(e.currentTarget.dataset.page);
    if (e.currentTarget.dataset.page=='goSearch') {
      wx.navigateTo({
        url: '/pages/search/search?quick=true&quickId='+e.currentTarget.dataset.id
      })
      return
    }
    let url=e.currentTarget.dataset.page
    let imgUrl=e.currentTarget.dataset.url
    if (imgUrl) {
      wx.navigateTo({
        url: '/pages/'+url+'/'+url+"?imgUrl="+imgUrl,
      })
    }else{
      wx.navigateTo({
        url: '/pages/'+url+'/'+url,
      })
    }
  },
  //前往搜索页
  goSearch() {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  //前往商品详情页
  goDetail(e) {
    wx.navigateTo({
      url: '/pages/goodsDetail/goodsDetail?goods_id='+e.currentTarget.dataset.row.id
    })
  },
  //前往扫码页
  goSaoMa() {
    wx.scanCode({　
      success: (res) => {　　
       console.log(res);
       let id=decodeURIComponent(res.result).split("?goods_id=")[1]
       wx.navigateTo({
         url: '/pages/goodsDetail/goodsDetail?goods_id='+id,
       })
      }　
  })
  },
  closeNew(){
    this.setData({
      newAieModel:false
    })
  },
  onShow(){
    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})